﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace SpaceMan
{
    class C_DrawText
    {
        Vector2 position, origin, size;
        SpriteFont font;
        Color color;
        string text;
        float rotation, scale;
        public C_DrawText(SpriteFont font)
        {

        }

        public void SetText(string text)
        {
            this.text = text;
            size = font.MeasureString(text);
        }

        public void Update(Vector2? Position, float? scale, float? rotation, Color? color)
        {
            if (position != null)
            {
                this.position = (Vector2)Position;
            }

            if (scale != null)
            {
                this.scale = (float)scale;
            }

            if (rotation != null)
            {
                this.rotation = (float)rotation;
            }

            if (color != null)
            {
                this.color = (Color)color;
            }
        }

        public void Draw(SpriteBatch spriteBatch, DrawMode drawMode, Rectangle drawSpace)
        {
            Rectangle rectangle = new Rectangle((int)position.X, (int)position.Y, (int)size.X, (int)size.Y);
            if (rectangle.Intersects(drawSpace))
            {
                if (drawMode == DrawMode.Texture)
                {
                    spriteBatch.DrawString(font, text, position, color, rotation, origin, scale, SpriteEffects.None, 0f);
                }

                else
                {
                    spriteBatch.DrawString(font, text, position, Color.Black, rotation, origin, scale, SpriteEffects.None, 0f);
                }
            }
        }
    }
}
